﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ExamClient;

namespace ExamClient
{
    /// <summary>
    /// Stellt eine Menüleiste abhängig von der Gruppenzugehörigkeit bereit
    /// </summary>
    public partial class MenuBarPage : Page
    {
        
        public MenuBarPage()
        {
            InitializeComponent();

            menu.Items.Remove(menu.Items[4]);
            menu.Items.Remove(menu.Items[3]);
            menu.Items.Remove(menu.Items[2]);
            menu.Items.Remove(menu.Items[1]);
            App.MenuBar = this;
        }

        /// <summary>
        /// Methode zum Ändern der MenuItems je nach Gruppenzugehörigkeit
        /// </summary>
        public void ChangeAccordingToGroup()
        {
            if (App.ServerConnection != null && App.ServerConnection.IsLoggedIn)
            {
                summary.IsEnabled = true;
                switch (App.UserAddress.UserGroup.GroupId)
                {
                    case 1:
                        menu.Items.Insert(1, user);
                        menu.Items.Insert(2, examsUser);
                        break;
                    case 2:
                        menu.Items.Insert(1, user);
                        menu.Items.Insert(2, examsDozent);
                        break;
                    case 4:
                        menu.Items.Insert(1, user);
                        menu.Items.Insert(2, administration);
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// <see cref="ClientMethods"/>
        /// </summary>
        /// <param name="activate"></param>
        public void ExamMode(Boolean activate)
        {
            foreach (MenuItem item in menu.Items)
            {
                item.IsEnabled = !activate;
            } 
        }

        private void close_Click(object sender, RoutedEventArgs e)
        {
            ClientMethods.ClientLogout();
            App.MainWindow.Close();
        }

        private void userInfos_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindow.center.Content = new UserInformationPage();
        }

        private void changePassword_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindow.center.Content = new PasswordPage();
        }

        private void summary_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindow.center.Content = App.SummaryPage;
        }

        private void futureExams_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindow.center.Content = new MainPage();
        }

        private void pastExams_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindow.center.Content = new MainPage(true);
        }

        private void info_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Kla - Client\nVersion " + App.VERSION
                + "\n\n von Kevin & Lüder"
                + "\n\u00a9 2011", "Info", MessageBoxButton.OK, MessageBoxImage.Question);
        }

        private void summaryExams_Click(object sender, RoutedEventArgs e)
        {
            App.MainWindow.center.Content = new MainPage(true);
        }
    }
}
